package com.molyfun.parents.activity.schoolonline.homework.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.schoolonline.homework.view.HomeWorkView;
import com.molyfun.parents.rest.bean.HomeWorkResponse;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:9/19/16.
 */
public class HomeWorkAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

//    private static final int TYPE_HEADER = 1001;
//    private static final int TYPE_CATEGORY = 1002;
    private Context mContext;

    private List<HomeWorkResponse.HomeWorkBean> mHomeWorkList;

    public HomeWorkAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void refreshData(List<HomeWorkResponse.HomeWorkBean> list){
        this.mHomeWorkList = list;
        notifyDataSetChanged();
    }

    public void clearAll(){
        if(mHomeWorkList != null){
            mHomeWorkList.clear();
            notifyDataSetChanged();
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new HomeWorkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_homework_brief_cell,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        HomeWorkViewHolder homeWorkViewHolder = (HomeWorkViewHolder) holder;
        homeWorkViewHolder.mHomeWorkLayout.initData(mHomeWorkList.get(position), position == (getItemCount() - 1));
    }



    @Override
    public int getItemCount() {
        if(mHomeWorkList == null){
            return 0;
        }else{
            return mHomeWorkList.size();
        }
    }


    class HomeWorkViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.homework_layout)
        HomeWorkView mHomeWorkLayout;

        public HomeWorkViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

}
